/*
 * gcode.h
 *
 * Copyright 2011 Pieter Agten
 *
 * This file is part of Yarf.
 *
 * Yarf is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Yarf is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Yarf.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @file   gcode.h
 * @author Pieter Agten (pieter.agten@gmail.com)
 * @date   20 sep 2011
 * @brief  The g-code component parses incoming g-code commands and calls the
 *         corresponding functions in the commands component.
 */

#ifndef GCODE_H
#define GCODE_H

#include <stdio.h>

#define GCODE_UNEXPECTED_LINE                    -8
#define GCODE_SYNTAX_ERROR                       -7
#define GCODE_COMMAND_UNKNOWN                    -6
#define GCODE_PARSE_COMMAND_CHECKSUM_FAILED      -5
#define GCODE_PARSE_COMMAND_READ_FAILURE         -4
#define GCODE_PARSE_COMMAND_UNEXPECTED_CHARACTER -3
#define GCODE_PARSE_COMMAND_SYNTAX_ERROR         -2
#define GCODE_PARSE_COMMAND_EMPTY                -1
#define GCODE_PARSE_COMMAND_SUCCESS               0
#define GCODE_PROCESS_COMMAND_SUCCESS             0

/**
 * Initializes the g-code component.
 *
 * @param host_stream  the stream from which to read the g-codes and on which
 *                     to output responses
 */
void gcode_init(FILE *host_stream);

/**
 * Reads and processes an incoming g-code command from the host stream.
 * 
 * @return \a GCODE_PROCESS_COMMAND_SUCCESS if the command was handled
 *          successfully, or one of the error codes if not.
 */
int gcode_process_command(void);

#endif //GCODE_H
